<?php

namespace Database\Seeders;

use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;

class CategorySeeder extends Seeder
{
    /**
     * Run the database seeds.
     */
    public function run(): void
    {
        DB::table('categories')->truncate();

        // 定义分类数据：一级分类包含 children 子数组表示子分类
        $categories = [
            [
                'name'        => '电子产品',
                'icon'        => 'electronics-icon.png',
                'status'      => 1,
                'description' => '各类电子数码产品',
                'children'    => [
                    [
                        'name'        => '手机',
                        'icon'        => 'phone-icon.png',
                        'status'      => 1,
                        'description' => '智能手机及配件'
                    ],
                    [
                        'name'        => '电脑',
                        'icon'        => 'computer-icon.png',
                        'status'      => 1,
                        'description' => '笔记本、台式机、平板'
                    ]
                ]
            ]
        ];
        insertNestedData('categories', $categories);
    }

}
